from typing import List
from models.transaction import Transaction

class TransactionService:
    def __init__(self):
        self.transactions: List[Transaction] = []
    
    def create_transaction(self, user, page: str, product, quantity: int, payment_method) -> bool:
        transaction = Transaction(user, page, product, quantity, payment_method)
        success = transaction.process()
        self.transactions.append(transaction)
        return success
    
    def get_all_transactions(self) -> List[Transaction]:
        return self.transactions
    
    def get_user_transactions(self, user_name: str) -> List[Transaction]:
        return [t for t in self.transactions if t.user.name == user_name]